package org.example.aigc.controller;

import org.example.aigc.mapper.CourseMapper;
import org.example.aigc.service.ChatService;
import org.example.aigc.utils.Reply;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/chat")
@RestController
public class ChatController {

    private final ChatService chatService;
    private final CourseMapper courseMapper;

    @Autowired
    public ChatController(ChatService chatService, CourseMapper courseMapper) {
        this.chatService = chatService;
        this.courseMapper = courseMapper;
    }

    /**
     * 语言模型聊天接口
     *
     * @param query    询问语句
     * @param courseId 该模型所属的课程id
     * @return 返回答复
     */
    @PostMapping("/chat")
    @ResponseBody
    public String knowledgeChat(
            @RequestParam("query") String query,
            @RequestParam("courseId") Long courseId
    ) {
        String ans = chatService.chat(query, courseMapper.selectById(courseId).getKnowledgeBaseName());
        System.out.println(new Reply("chat").ok(0, "成功"));
        return ans;
    }
}
